package main

import (
	"flag"
	"fmt"
	mysql "sems/database"
	"sems/router"
	settings "sems/setting"
	"sems/util/oss"
)

func main() {
	var confFile string
	flag.StringVar(&confFile, "conf", "./config/config.yaml", "配置文件")
	flag.Parse()
	// 加载配置
	if err := settings.Init(); err != nil {
		fmt.Printf("load config failed, err:%v\n", err)
		return
	}
	if err := mysql.Init(settings.Conf.MySQLConfig); err != nil {
		fmt.Printf("init mysql failed, err:%v\n", err)
		return
	}
	defer mysql.Close() // 程序退出关闭数据库连接
	oss.Init(settings.Conf.OssConfig)

	// 示例：使用ConnectToRabbitMQ函数
	//ch, conn, err := rabbitmq.ConnectToRabbitMQ()
	//if err != nil {
	//	log.Fatalf("Could not connect to RabbitMQ: %v", err)
	//}
	//
	//defer conn.Close() // 确保关闭连接
	//defer ch.Close()   // 确保关闭通道

	// 注册路由
	r := router.SetupRouter(settings.Conf.Mode) //传入初始化的模式

	err := r.Run(fmt.Sprintf(":%d", settings.Conf.Port))
	if err != nil {
		fmt.Printf("run server failed, err:%v\n", err)
		return
	}
}
